<?php
include("../../tools/session.php");
include("../../tools/controls.php");
include("../../tools/pub.php");

// 如果登录失败、无权限访问，那么采取相应措施
if (!($is_login_success === true)) { session_hop_page("../index.php"); exit(); }
if (!power_check(0)) { include("tpl-inc-wp.php"); $tpl->display($oa_tpl_path . "/no-power.html"); exit(); }

/*-- 以下是实际内容 --*/
$page_status = $_POST["page_status"];
if (!$page_status)
{
   include("../../tools/mysql.php");
   include("tpl-inc-wp.php");
   db_connect();
   
   $sql = "SELECT tel, phone, qq, email, address, photo
			FROM archive WHERE username='" . $_SESSION["user"]["username"] . "'";
   $re = db_query_once($sql);

   $tpl->assign("tel", $re["tel"]);
   $tpl->assign("phone", $re["phone"]);
   $tpl->assign("qq", $re["qq"]);
   $tpl->assign("email", $re["email"]);
   $tpl->assign("address", $re["address"]);
   $tpl->assign("photo", $re["photo"]);
   $tpl->display($oa_tpl_path . "/default/personal_information.html");
}
// 如果 $page_status 等于 1，那么处理数据，并且返回处理信息
elseif ($page_status == 1)
{
   /* 获取数据 */
   $tel = $_POST["tel"];
   $phone = $_POST["phone"];
   $qq = $_POST["qq"];
   $email = $_POST["email"];
   $address = $_POST["address"];
   $reup_photo = $_POST["reup_photo"];
   
   // $alert_msg = array("Success: 个人信息修改成功！", "Error: 个人信息修改失败！");
   
   // 加载函数库
   include("../../tools/mysql.php");
   db_connect();
   
   $sql = "SELECT count(archive_id) num FROM archive WHERE username='"
	 . $_SESSION["user"]["username"] . "'";
   $re = db_query_once($sql);
   
   $sql2 = ($re["num"] != 0)
	 ? ("UPDATE archive SET tel='" . $tel
		. "', phone='" . $phone
		. "', qq='" . $qq
		. "', email='" . $email
		. "', address='" . $address
		. "', photo='" . $reup_photo
		. "' WHERE username='" . $_SESSION["user"]["username"] . "'")
	 : ("INSERT INTO archive(username, tel, phone, qq, email, address, photo) VALUES('"
		. $_SESSION["user"]["username"]
		. "', '" . $tel
		. "', '" . $phone
		. "', '" . $qq
		. "', '" . $email
		. "', '" . $address
		. "', '" . $reup_photo
		. "')");
   $re2 = db_exec($sql2);
   
   // echo ($re2) ? $alert_msg[0] : $alert_msg[1];
   $log_str = array("修改“" . $_SESSION["user"]["username"] . "”的个人信息成功！", "修改个人信息失败！");
   echo check_status_write_to_log($re2, $log_str, TRUE);
}

?>
